using System;
using NFreeMarker.Template;

namespace NFreeMarker.Ext.Beans
{
    /**
     * @author Attila Szegedi
     * @version $Id: SequenceAdapter.java,v 1.2 2005/06/12 19:03:04 szegedia Exp $
     */
    class SequenceAdapter : ITemplateModelAdapter // TODO: AbstractList
    {
        private readonly BeansWrapper _wrapper;
        private readonly ITemplateSequenceModel _model;

        internal SequenceAdapter(ITemplateSequenceModel model, BeansWrapper wrapper)
        {
            _model = model;
            _wrapper = wrapper;
        }
        
        public ITemplateModel GetTemplateModel()
        {
            return _model;
        }
        
        public int Size()
        {
            try
            {
                return _model.Size();
            }
            catch (TemplateModelException e)
            {
                //throw new UndeclaredThrowableException(e);
                throw new NotImplementedException();
            }
        }
        
        public object Get(int index)
        {
            try
            {
                return _wrapper.Unwrap(_model.Get(index));
            }
            catch (TemplateModelException e)
            {
                //throw new UndeclaredThrowableException(e);
                throw new NotImplementedException();
            }
        }
    }
}